-
Notifications
You must be signed in to change notification settings - Fork 0
/
Diagonal Difference.c
63 lines (62 loc) · 1.78 KB
/
Diagonal Difference.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
* @Repository HackerRank Soulutions
* @file Diagonal Difference
* @author Abdelrahman Ahmed Moussa ([email protected])
* @copyright Copyright (c) 2024
*
*/
/*------------------------------------------------------------------------------*/
/* */
/* Solution 01 */
/* */
/*------------------------------------------------------------------------------*/
int diagonalDifference(int arr_rows, int arr_columns, int** arr)
{
int i,j,d1=0,d2=0;
j=arr_columns-1;
for (i=0 ; i<arr_rows ; i++,j--)
{
d1=d1+arr[i][i]; //i,i not i,j
d2=d2+arr[i][j];
}
if (d1>=d2)
{
return d1-d2;
}
else
{
return d2-d1;
}
}
/*------------------------------------------------------------------------------*/
/* */
/* Solution 02 */
/* */
/*------------------------------------------------------------------------------*/
/*
int diagonalDifference(int arr_rows, int arr_columns, int** arr) {
int i,j,d1=0,d2=0;
for (i=0 ; i<arr_rows ; i++)
{
for (j=0 ; j<arr_columns ; j++)
{
if (i==j)
{
d1=d1+arr[i][j];
}
if ((i+j)==(arr_columns-1))
{
d2=d2+arr[i][j];
}
}
}
if (d1>=d2)
{
return d1-d2;
}
else
{
return d2-d1;
}*/
}
*/